package com.sunda.spmsweb.ordercontroller;

import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsorder.service.IOrderTraceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: spms
 * @description:
 * @author: Wayne Wu
 * @create: 2022-01-07 16:14
 **/

@Slf4j
@RestController
@RequestMapping("/orderTrace")
@Api(tags = "请购单全流程追溯(箱码状态)", description = "请购单全流程追溯(箱码状态)")
public class OrderProcessTraceabilityController {

    @Autowired
    IOrderTraceService iOrderTraceService;


    @RequestMapping("/getWaitingForArrivalBoxList")
    @ApiOperation(value = "获取自管仓待到货箱码列表", notes = "获取自管仓待到货箱码\n" +
            "SPMS系统有箱码但自管仓无库存且无操作日志，则认为自管仓待到货；日期参数为箱码在SPMS创建起止时间；\n" +
            "示例参数 beginDate = 2021-09-01, endDate = 2021-11-01\n" +
            "\n", httpMethod = "POST")
    public ResponseResult getWaitingForArrivalBoxList(String beginDate, String endDate){
        try {
            return ResponseResult.success().add("waitingForArrivalBoxList", iOrderTraceService.getWaitingForArrivalBoxList(beginDate, endDate));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getCN01BoxList")
    @ApiOperation(value = "获取自管仓在库箱码列表", notes = "获取自管仓在库箱码列表\n" +
            "自管仓内的箱码列表，直接从储位库存获取，即自管仓在库箱码列表；\n" +
            "werks = CN01，whsLocationCode = 1061，传空则查询CN01所有仓库；\n" +
            "日期参数为箱码最后在仓库创建起止时间；传空默认范围为近六个月数据；\n" +
            "示例参数 beginDate = 2021-09-01, endDate = 2021-11-01\n" +
            "\n", httpMethod = "POST")
    public ResponseResult getCN01BoxList(String whsLocationCode, String beginDate, String endDate){
        try {
            String werks = "CN01";
            return ResponseResult.success().add("CN01BoxList", iOrderTraceService.getCN01BoxList(werks, whsLocationCode, beginDate, endDate));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOverseaOnTheWayBoxList")
    @ApiOperation(value = "获取海外仓在途箱码列表", notes = "获取海外仓在途箱码列表\n" +
            "海运/转储在途库存，从南沙箱码出库日志提取每个箱码最新一条，OPERATION_TYPE = 3, 16, 22 即为在途；\n" +
            "日期参数为箱码最后操作日志创建起止时间；传空默认范围为近六个月数据；\n" +
            "示例参数 beginDate = 2021-09-01, endDate = 2021-11-01\n" +
            "\n", httpMethod = "POST")
    public ResponseResult getOverseaOnTheWayBoxList(String beginDate, String endDate){
        try {
            return ResponseResult.success().add("waitingForArrivalBoxList", iOrderTraceService.getOverseaOnTheWayBoxList(beginDate, endDate));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOverseaArrivalBoxList")
    @ApiOperation(value = "获取海外仓已到货箱码列表", notes = "获取海外仓已到货箱码列表\n" +
            "海外到货，按箱码到货日志获取；OPERATION_TYPE = 21 表示海外已到货；\n" +
            "日期参数为箱码最后操作日志创建起止时间；传空默认范围为近六个月数据；\n" +
            "示例参数 beginDate = 2021-09-01, endDate = 2021-11-01\n" +
            "\n", httpMethod = "POST")
    public ResponseResult getOverseaArrivalBoxList(String beginDate, String endDate){
        try {
            return ResponseResult.success().add("waitingForArrivalBoxList", iOrderTraceService.getOverseaArrivalBoxList(beginDate, endDate));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

}
